package Java_keshe;
import java.util.Scanner;
import java.awt.*;
import java.awt.event.*;

public class Demo extends Frame implements ActionListener {
    private Label shuru = new Label("请输入你要计算的数学表达式：");
    private TextField input = new TextField(30);
    private Button jisuan = new Button("计算");
    private Label shuchu = new Label("结果: ");
    private Label display = new Label("");
    private Panel shang  = new Panel();
    private Panel xia = new Panel();
    public Demo(){
        setLayout(new BorderLayout());
        shang.add(shuru);
        shang.add(input);
        shang.add(jisuan);
        xia.add(shuchu);
        xia.add(display);
        setTitle("计算数学表达式");
        add(shang,BorderLayout.NORTH);
        add(xia);
        pack();
        setVisible(true);
        jisuan.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e){
        String biaodashi;
        double jieguo;
        biaodashi=input.getText();   //输入待计算表达式
        jieguo=BianBieLei.bianbie(biaodashi);
        display.setText(""+jieguo);
    }

    public static void main(String args[]) {
        Demo d = new Demo();
        d.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }

}
